<?php
declare (strict_types = 1);

namespace app\api\controller\yuql;

use app\logic\yuql\GeoLogic;
use think\Request;

class SearchHouse
{

    /**
     * yuql
     * 房源添加
     * @param Request $request
     * @return \think\response\Json
     */
    public function houseAdd(Request $request){
        try {
            $params = $request->get();
            $result = GeoLogic::houseAdd($params);
            return writeJson(1002,$result,'房源添加成功');
        } catch (\Exception $e){
            return writeJson(1002,'',$e->getMessage());
        }
    }

    /**
     * yuql
     * 搜索房源
     * @param Request $request
     * @return \think\response\Json
     */
    public function searchHouse(Request $request){
        try {
            $params = $request->get();
            $result = GeoLogic::searchHouse($params);
            foreach ($result as $v){
                $house = $v[0];  //房源地址
                $distance = $v[1];  //距离
            }
            $result = $house . '距离你' . $distance . 'km';
            return writeJson(1002,$result,'success');
        } catch (\Exception $e){
            return writeJson(1002,'',$e->getMessage());
        }
    }

}
